home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / xserver-xorg.postinst < prev    next >
Encoding:
Text File  |  2009-04-03  |  62.7 KB  |  1,939 lines

  1. #!/bin/sh
  2. # Debian xserver-xorg package post-installation script
  3. # Copyright 1998-2004 Branden Robinson.
  4. # Copyright 2004-2005 Canonical Ltd.
  5. # Licensed under the GNU General Public License, version 2.  See the file
  6. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  7. # Acknowledgements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  8.  
  9. set -e
  10.  
  11. # source debconf library
  12. . /usr/share/debconf/confmodule
  13.  
  14. THIS_PACKAGE=xserver-xorg
  15. THIS_SCRIPT=postinst
  16.  
  17. # $Id$
  18.  
  19. # This is the X Strike Force shell library for X Window System package
  20. # maintainer scripts.  It serves to define shell functions commonly used by
  21. # such packages, and performs some error checking necessary for proper operation
  22. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  23. # invoke the functions defined here to accomplish package installation and
  24. # removal tasks.
  25.  
  26. # If you are reading this within a Debian package maintainer script (e.g.,
  27. # /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  28. # skip past this library by scanning forward in this file to the string
  29. # "GOBSTOPPER".
  30.  
  31. SOURCE_VERSION=1:7.4~5ubuntu18
  32. OFFICIAL_BUILD=
  33.  
  34. # Use special abnormal exit codes so that problems with this library are more
  35. # easily tracked down.
  36. SHELL_LIB_INTERNAL_ERROR=86
  37. SHELL_LIB_THROWN_ERROR=74
  38. SHELL_LIB_USAGE_ERROR=99
  39.  
  40. # old -> new variable names
  41. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  42.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  43. fi
  44. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  45.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  46. fi
  47.  
  48. # initial sanity checks
  49. if [ -z "$THIS_PACKAGE" ]; then
  50.   cat >&2 <<EOF
  51. Error: package maintainer script attempted to use shell library without
  52. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  53. version, and the text of this error message to the Debian Bug Tracking System.
  54. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  55. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  56. "doc-debian" package, or install the "reportbug" package and use the command of
  57. the same name to file a report against version $SOURCE_VERSION of this package.
  58. EOF
  59.   exit $SHELL_LIB_USAGE_ERROR
  60. fi
  61.  
  62. if [ -z "$THIS_SCRIPT" ]; then
  63.   cat >&2 <<EOF
  64. Error: package maintainer script attempted to use shell library without
  65. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  66. version, and the text of this error message to the Debian Bug Tracking System.
  67. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  68. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  69. "doc-debian" package, or install the "reportbug" package and use the command of
  70. the same name to file a report against version $SOURCE_VERSION of the
  71. "$THIS_PACKAGE" package.
  72. EOF
  73.   exit $SHELL_LIB_USAGE_ERROR
  74. fi
  75.  
  76. ARCHITECTURE="$(dpkg --print-installation-architecture)"
  77.  
  78. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  79.   RECONFIGURE="true"
  80. else
  81.   RECONFIGURE=
  82. fi
  83.  
  84. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  85.   FIRSTINST="yes"
  86. fi
  87.  
  88. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  89.   UPGRADE="yes"
  90. fi
  91.  
  92. trap "message;\
  93.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  94.       message;\
  95.       exit 1" HUP INT QUIT TERM
  96.  
  97. reject_nondigits () {
  98.   # syntax: reject_nondigits [ operand ... ]
  99.   #
  100.   # scan operands (typically shell variables whose values cannot be trusted) for
  101.   # characters other than decimal digits and barf if any are found
  102.   while [ -n "$1" ]; do
  103.     # does the operand contain anything but digits?
  104.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  105.       # can't use die(), because it wraps message() which wraps this function
  106.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  107.            "possibly malicious garbage \"$1\"" >&2
  108.       exit $SHELL_LIB_THROWN_ERROR
  109.     fi
  110.     shift
  111.   done
  112. }
  113.  
  114. reject_whitespace () {
  115.   # syntax: reject_whitespace [ operand ]
  116.   #
  117.   # scan operand (typically a shell variable whose value cannot be trusted) for
  118.   # whitespace characters and barf if any are found
  119.   if [ -n "$1" ]; then
  120.     # does the operand contain any whitespace?
  121.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  122.       # can't use die(), because I want to avoid forward references
  123.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  124.            "possibly malicious garbage \"$1\"" >&2
  125.       exit $SHELL_LIB_THROWN_ERROR
  126.     fi
  127.   fi
  128. }
  129.  
  130. reject_unlikely_path_chars () {
  131.   # syntax: reject_unlikely_path_chars [ operand ... ]
  132.   #
  133.   # scan operands (typically shell variables whose values cannot be trusted) for
  134.   # characters unlikely to be seen in a path and which the shell might
  135.   # interpret and barf if any are found
  136.   while [ -n "$1" ]; do
  137.     # does the operand contain any funny characters?
  138.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  139.       # can't use die(), because I want to avoid forward references
  140.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  141.            "encountered possibly malicious garbage \"$1\"" >&2
  142.       exit $SHELL_LIB_THROWN_ERROR
  143.     fi
  144.     shift
  145.   done
  146. }
  147.  
  148. # Query the terminal to establish a default number of columns to use for
  149. # displaying messages to the user.  This is used only as a fallback in the
  150. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  151. # the script is running, and this cannot, only being calculated once.)
  152. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  153. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  154.   DEFCOLUMNS=80
  155. fi
  156.  
  157. message () {
  158.   # pretty-print messages of arbitrary length
  159.   reject_nondigits "$COLUMNS"
  160.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  161. }
  162.  
  163. observe () {
  164.   # syntax: observe message ...
  165.   #
  166.   # issue observational message suitable for logging someday when support for
  167.   # it exists in dpkg
  168.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  169.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  170.   fi
  171. }
  172.  
  173. warn () {
  174.   # syntax: warn message ...
  175.   #
  176.   # issue warning message suitable for logging someday when support for
  177.   # it exists in dpkg; also send to standard error
  178.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  179. }
  180.  
  181. die () {
  182.   # syntax: die message ...
  183.   #
  184.   # exit script with error message
  185.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  186.   exit $SHELL_LIB_THROWN_ERROR
  187. }
  188.  
  189. internal_error () {
  190.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  191.   message "internal error: $*"
  192.   if [ -n "$OFFICIAL_BUILD" ]; then
  193.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  194.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  195.             "Tracking System.  Include all messages above that mention the" \
  196.             "$THIS_PACKAGE package.  Visit " \
  197.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  198.             "instructions, read the file" \
  199.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  200.             "package, or install the reportbug package and use the command of" \
  201.             "the same name to file a report."
  202.   fi
  203.   exit $SHELL_LIB_INTERNAL_ERROR
  204. }
  205.  
  206. usage_error () {
  207.   message "usage error: $*"
  208.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  209.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  210.           "Tracking System.  Include all messages above that mention the" \
  211.           "$THIS_PACKAGE package.  Visit " \
  212.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  213.           "instructions, read the file" \
  214.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  215.           "package, or install the reportbug package and use the command of" \
  216.           "the same name to file a report."
  217.   exit $SHELL_LIB_USAGE_ERROR
  218. }
  219.  
  220.  
  221. maplink () {
  222.   # returns what symlink should point to; i.e., what the "sane" answer is
  223.   # Keep this in sync with the debian/*.links files.
  224.   # This is only needed for symlinks to directories.
  225.   #
  226.   # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
  227.   # If we've stopped using this function, fixing it might enable us to re-enable
  228.   # it again and catch more errors.
  229.   case "$1" in
  230.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  231.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  232.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  233.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  234.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  235.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  236.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  237.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  238.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  239.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  240.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  241.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  242.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  243.     /usr/bin/X11) echo ../X11R6/bin ;;
  244.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  245.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  246.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  247.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  248.   esac
  249. }
  250.  
  251. analyze_path () {
  252.   # given a supplied set of pathnames, break each one up by directory and do an
  253.   # ls -dl on each component, cumulatively; i.e.
  254.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  255.   # Thanks to Randolph Chung for this clever hack.
  256.  
  257.   local f g
  258.  
  259.   while [ -n "$1" ]; do
  260.     reject_whitespace "$1"
  261.     g=
  262.     message "Analyzing $1:"
  263.     for f in $(echo "$1" | tr / \  ); do
  264.       if [ -e /$g$f ]; then
  265.         ls -dl /$g$f /$g$f.dpkg-* 2> /dev/null || true
  266.         g=$g$f/
  267.       else
  268.         message "/$g$f: nonexistent; directory contents of /$g:"
  269.         ls -l /$g
  270.         break
  271.       fi
  272.     done
  273.     shift
  274.   done
  275. }
  276.  
  277. find_culprits () {
  278.   local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  279.     msg
  280.  
  281.   reject_whitespace "$1"
  282.   message "Searching for overlapping packages..."
  283.   dpkg_info_dir=/var/lib/dpkg/info
  284.   if [ -d $dpkg_info_dir ]; then
  285.     if [ "$(echo $dpkg_info_dir/*.list)" != "$dpkg_info_dir/*.list" ]; then
  286.       possible_culprits=$(ls -1 $dpkg_info_dir/*.list | egrep -v \
  287.         "(xbase-clients|x11-common|xfs|xlibs)")
  288.       if [ -n "$possible_culprits" ]; then
  289.         smoking_guns=$(grep -l "$1" $possible_culprits || true)
  290.         if [ -n "$smoking_guns" ]; then
  291.           bad_packages=$(printf "\\n")
  292.           for f in $smoking_guns; do
  293.             # too bad you can't nest parameter expansion voodoo
  294.             p=${f%*.list}      # strip off the trailing ".list"
  295.             package=${p##*/}   # strip off the directories
  296.             bad_packages=$(printf "%s\n%s" "$bad_packages" "$package")
  297.           done
  298.           msg=$(cat <<EOF
  299. The following packages appear to have file overlaps with the X.Org packages;
  300. these packages are either very old, or in violation of Debian Policy.  Try
  301. upgrading each of these packages to the latest available version if possible:
  302. for example, with the command "apt-get install".  If no newer version of a
  303. package is available, you will have to remove it; for example, with the command
  304. "apt-get remove".  If even the latest available version of the package has
  305. this file overlap, please file a bug against that package with the Debian Bug
  306. Tracking System.  You may want to refer the package maintainer to section 12.8
  307. of the Debian Policy manual.
  308. EOF
  309. )
  310.           message "$msg"
  311.           message "The overlapping packages are: $bad_packages"
  312.         else
  313.           message "no overlaps found."
  314.         fi
  315.       fi
  316.     else
  317.       message "cannot search; no matches for $dpkg_info_dir/*.list."
  318.     fi
  319.   else
  320.     message "cannot search; $dpkg_info_dir does not exist."
  321.   fi
  322. }
  323.  
  324. # we require a readlink command or shell function
  325. if ! which readlink > /dev/null 2>&1; then
  326.   message "The readlink command was not found.  Please install version" \
  327.           "1.13.1 or later of the debianutils package."
  328.   readlink () {
  329.     # returns what symlink in $1 actually points to
  330.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  331.   }
  332. fi
  333.  
  334. check_symlink () {
  335.   # syntax: check_symlink symlink
  336.   #
  337.   # See if specified symlink points where it is supposed to.  Return 0 if it
  338.   # does, and 1 if it does not.
  339.   #
  340.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  341.  
  342.   local symlink
  343.  
  344.   # validate arguments
  345.   if [ $# -ne 1 ]; then
  346.     usage_error "check_symlink() called with wrong number of arguments;" \
  347.                 "expected 1, got $#"
  348.     exit $SHELL_LIB_USAGE_ERROR
  349.   fi
  350.  
  351.   symlink="$1"
  352.  
  353.   if [ "$(maplink "$symlink")" = "$(readlink "$symlink")" ]; then
  354.     return 0
  355.   else
  356.     return 1
  357.   fi
  358. }
  359.  
  360. check_symlinks_and_warn () {
  361.   # syntax: check_symlinks_and_warn symlink ...
  362.   #
  363.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  364.   #
  365.   # Call this function from a preinst script in the event $1 is "upgrade" or
  366.   # "install".
  367.  
  368.   local errmsg symlink
  369.  
  370.   # validate arguments
  371.   if [ $# -lt 1 ]; then
  372.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  373.                 "arguments; expected at least 1, got $#"
  374.     exit $SHELL_LIB_USAGE_ERROR
  375.   fi
  376.  
  377.   while [ -n "$1" ]; do
  378.     symlink="$1"
  379.     if [ -L "$symlink" ]; then
  380.       if ! check_symlink "$symlink"; then
  381.         observe "$symlink symbolic link points to wrong location" \
  382.                 "$(readlink "$symlink"); removing"
  383.         rm "$symlink"
  384.       fi
  385.     elif [ -e "$symlink" ]; then
  386.       errmsg="$symlink exists and is not a symbolic link; this package cannot"
  387.       errmsg="$errmsg be installed until this"
  388.       if [ -f "$symlink" ]; then
  389.         errmsg="$errmsg file"
  390.       elif [ -d "$symlink" ]; then
  391.         errmsg="$errmsg directory"
  392.       else
  393.         errmsg="$errmsg thing"
  394.       fi
  395.       errmsg="$errmsg is removed"
  396.       die "$errmsg"
  397.     fi
  398.     shift
  399.   done
  400. }
  401.  
  402. check_symlinks_and_bomb () {
  403.   # syntax: check_symlinks_and_bomb symlink ...
  404.   #
  405.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  406.   #
  407.   # Call this function from a postinst script.
  408.  
  409.   local problem symlink
  410.  
  411.   # validate arguments
  412.   if [ $# -lt 1 ]; then
  413.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  414.                 "arguments; expected at least 1, got $#"
  415.     exit $SHELL_LIB_USAGE_ERROR
  416.   fi
  417.  
  418.   while [ -n "$1" ]; do
  419.     problem=
  420.     symlink="$1"
  421.     if [ -L "$symlink" ]; then
  422.       if ! check_symlink "$symlink"; then
  423.         problem=yes
  424.         warn "$symlink symbolic link points to wrong location" \
  425.              "$(readlink "$symlink")"
  426.       fi
  427.     elif [ -e "$symlink" ]; then
  428.       problem=yes
  429.       warn "$symlink is not a symbolic link"
  430.     else
  431.       problem=yes
  432.       warn "$symlink symbolic link does not exist"
  433.     fi
  434.     if [ -n "$problem" ]; then
  435.       analyze_path "$symlink" "$(readlink "$symlink")"
  436.       find_culprits "$symlink"
  437.       die "bad symbolic links on system"
  438.     fi
  439.     shift
  440.   done
  441. }
  442.  
  443. font_update () {
  444.   # run $UPDATECMDS in $FONTDIRS
  445.  
  446.   local dir cmd shortcmd x_font_dir_prefix
  447.  
  448.   x_font_dir_prefix="/usr/share/fonts/X11"
  449.  
  450.   if [ -z "$UPDATECMDS" ]; then
  451.     usage_error "font_update() called but \$UPDATECMDS not set"
  452.   fi
  453.   if [ -z "$FONTDIRS" ]; then
  454.     usage_error "font_update() called but \$FONTDIRS not set"
  455.   fi
  456.  
  457.   reject_unlikely_path_chars "$UPDATECMDS"
  458.   reject_unlikely_path_chars "$FONTDIRS"
  459.  
  460.   for dir in $FONTDIRS; do
  461.     if [ -d "$x_font_dir_prefix/$dir" ]; then
  462.       for cmd in $UPDATECMDS; do
  463.         if which "$cmd" > /dev/null 2>&1; then
  464.           shortcmd=${cmd##*/}
  465.           observe "running $shortcmd in $dir font directory"
  466.       cmd_opts=
  467.           if [ "$shortcmd" = "update-fonts-alias" ]; then
  468.             cmd_opts=--x11r7-layout
  469.           fi
  470.           if [ "$shortcmd" = "update-fonts-dir" ]; then
  471.             cmd_opts=--x11r7-layout
  472.           fi
  473.           if [ "$shortcmd" = "update-fonts-scale" ]; then
  474.             cmd_opts=--x11r7-layout
  475.           fi
  476.           $cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
  477.                               "failed; font directory data may not" \
  478.                               "be up to date"
  479.         else
  480.           warn "$cmd not found; not updating corresponding $dir font" \
  481.                "directory data"
  482.         fi
  483.       done
  484.     else
  485.       warn "$dir is not a directory; not updating font directory data"
  486.     fi
  487.   done
  488. }
  489.  
  490. remove_conffile_prepare () {
  491.   # syntax: remove_conffile_prepare filename official_md5sum ...
  492.   #
  493.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  494.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  495.   # operands provided, then prepare the conffile for removal from the system.
  496.   # We defer actual deletion until the package is configured so that we can
  497.   # roll this operation back if package installation fails.
  498.   #
  499.   # Call this function from a preinst script in the event $1 is "upgrade" or
  500.   # "install" and verify $2 to ensure the package is being upgraded from a
  501.   # version (or installed over a version removed-but-not-purged) prior to the
  502.   # one in which the conffile was obsoleted.
  503.  
  504.   local conffile current_checksum
  505.  
  506.   # validate arguments
  507.   if [ $# -lt 2 ]; then
  508.     usage_error "remove_conffile_prepare() called with wrong number of" \
  509.                 "arguments; expected at least 2, got $#"
  510.     exit $SHELL_LIB_USAGE_ERROR
  511.   fi
  512.  
  513.   conffile="$1"
  514.   shift
  515.  
  516.   # does the conffile even exist?
  517.   if [ -e "$conffile" ]; then
  518.     # calculate its checksum
  519.     current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
  520.     # compare it to each supplied checksum
  521.     while [ -n "$1" ]; do
  522.       if [ "$current_checksum" = "$1" ]; then
  523.         # we found a match; move the confffile and stop looking
  524.         observe "preparing obsolete conffile $conffile for removal"
  525.         mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
  526.         break
  527.       fi
  528.       shift
  529.     done
  530.   fi
  531. }
  532.  
  533. remove_conffile_lookup () {
  534.   # syntax: remove_conffile_lookup package filename
  535.   #
  536.   # Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
  537.   # if it matches the actual file's md5sum.
  538.   #
  539.   # Call this function when you would call remove_conffile_prepare but only
  540.   # want to check against dpkg's status database instead of known checksums.
  541.  
  542.   local package conffile old_md5sum
  543.  
  544.   # validate arguments
  545.   if [ $# -ne 2 ]; then
  546.     usage_error "remove_conffile_lookup() called with wrong number of" \
  547.                 "arguments; expected 1, got $#"
  548.     exit $SHELL_LIB_USAGE_ERROR
  549.   fi
  550.  
  551.   package="$1"
  552.   conffile="$2"
  553.  
  554.   if ! [ -e "$conffile" ]; then
  555.     return
  556.   fi
  557.   old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$package" | \
  558.     awk '{ if (match($0, "^ '"$conffile"' ")) print $2}')"
  559.   if [ -n "$old_md5sum" ]; then
  560.     remove_conffile_prepare "$conffile" "$old_md5sum"
  561.   fi
  562. }
  563.  
  564. remove_conffile_commit () {
  565.   # syntax: remove_conffile_commit filename
  566.   #
  567.   # Complete the removal of a conffile "filename" that has become obsolete.
  568.   #
  569.   # Call this function from a postinst script after having used
  570.   # remove_conffile_prepare() in the preinst.
  571.  
  572.   local conffile
  573.  
  574.   # validate arguments
  575.   if [ $# -ne 1 ]; then
  576.     usage_error "remove_conffile_commit() called with wrong number of" \
  577.                 "arguments; expected 1, got $#"
  578.     exit $SHELL_LIB_USAGE_ERROR
  579.   fi
  580.  
  581.   conffile="$1"
  582.  
  583.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  584.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  585.     observe "committing removal of obsolete conffile $conffile"
  586.     rm "$conffile.$THIS_PACKAGE-tmp"
  587.   fi
  588. }
  589.  
  590. remove_conffile_rollback () {
  591.   # syntax: remove_conffile_rollback filename
  592.   #
  593.   # Roll back the removal of a conffile "filename".
  594.   #
  595.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  596.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  597.   # preinst.
  598.  
  599.   local conffile
  600.  
  601.   # validate arguments
  602.   if [ $# -ne 1 ]; then
  603.     usage_error "remove_conffile_rollback() called with wrong number of" \
  604.                 "arguments; expected 1, got $#"
  605.     exit $SHELL_LIB_USAGE_ERROR
  606.   fi
  607.  
  608.   conffile="$1"
  609.  
  610.   # if the temporary file created by remove_conffile_prepare() exists, move it
  611.   # back
  612.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  613.     observe "rolling back removal of obsolete conffile $conffile"
  614.     mv "$conffile.$THIS_PACKAGE-tmp" "$conffile"
  615.   fi
  616. }
  617.  
  618. replace_conffile_with_symlink_prepare () {
  619.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  620.   # official_md5sum ...
  621.   #
  622.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  623.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  624.   # operands provided, then prepare the conffile for removal from the system.
  625.   # We defer actual deletion until the package is configured so that we can
  626.   # roll this operation back if package installation fails. Otherwise copy it
  627.   # to newfilename and let dpkg handle it through conffiles mechanism.
  628.   #
  629.   # Call this function from a preinst script in the event $1 is "upgrade" or
  630.   # "install" and verify $2 to ensure the package is being upgraded from a
  631.   # version (or installed over a version removed-but-not-purged) prior to the
  632.   # one in which the conffile was obsoleted.
  633.  
  634.   local conffile current_checksum
  635.  
  636.   # validate arguments
  637.   if [ $# -lt 3 ]; then
  638.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  639.                 " number of arguments; expected at least 3, got $#"
  640.     exit $SHELL_LIB_USAGE_ERROR
  641.   fi
  642.  
  643.   oldconffile="$1"
  644.   shift
  645.   newconffile="$1"
  646.   shift
  647.  
  648.   remove_conffile_prepare "$_oldconffile" "$@"
  649.   # If $oldconffile still exists, then md5sums didn't match.
  650.   # Copy it to new one.
  651.   if [ -f "$oldconffile" ]; then
  652.     cp "$oldconffile" "$newconffile"
  653.   fi
  654.  
  655. }
  656.  
  657. replace_conffile_with_symlink_commit () {
  658.   # syntax: replace_conffile_with_symlink_commit oldfilename
  659.   #
  660.   # Complete the removal of a conffile "oldfilename" that has been
  661.   # replaced by a symlink.
  662.   #
  663.   # Call this function from a postinst script after having used
  664.   # replace_conffile_with_symlink_prepare() in the preinst.
  665.  
  666.   local conffile
  667.  
  668.   # validate arguments
  669.   if [ $# -ne 1 ]; then
  670.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  671.                 "number of arguments; expected 1, got $#"
  672.     exit $SHELL_LIB_USAGE_ERROR
  673.   fi
  674.  
  675.   conffile="$1"
  676.  
  677.   remove_conffile_commit "$conffile"
  678. }
  679.  
  680. replace_conffile_with_symlink_rollback () {
  681.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  682.   #
  683.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  684.   # "newfilename".
  685.   #
  686.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  687.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  688.   # from a version (or install over a version removed-but-not-purged) prior
  689.   # to the one in which the conffile was obsoleted.
  690.   # You should have  used replace_conffile_with_symlink_prepare() in the
  691.   # preinst.
  692.  
  693.   local conffile
  694.  
  695.   # validate arguments
  696.   if [ $# -ne 2 ]; then
  697.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  698.                 "number of arguments; expected 2, got $#"
  699.     exit $SHELL_LIB_USAGE_ERROR
  700.   fi
  701.  
  702.   oldconffile="$1"
  703.   newconffile="$2"
  704.  
  705.   remove_conffile_rollback "$_oldconffile"
  706.   if [ -f "$newconffile" ]; then
  707.     rm "$newconffile"
  708.   fi
  709. }
  710.  
  711. run () {
  712.   # syntax: run command [ argument ... ]
  713.   #
  714.   # Run specified command with optional arguments and report its exit status.
  715.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  716.   # or commands whose failure is not fatal to us.
  717.   #
  718.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  719.   # those cases the return value of the debconf command *must* be checked
  720.   # before the string returned by debconf is used for anything.
  721.  
  722.   local retval
  723.  
  724.   # validate arguments
  725.   if [ $# -lt 1 ]; then
  726.     usage_error "run() called with wrong number of arguments; expected at" \
  727.                 "least 1, got $#"
  728.     exit $SHELL_LIB_USAGE_ERROR
  729.   fi
  730.  
  731.   "$@" || retval=$?
  732.  
  733.   if [ ${retval:-0} -ne 0 ]; then
  734.     observe "command \"$*\" exited with status $retval"
  735.   fi
  736. }
  737.  
  738. register_x_lib_dir_with_ld_so () {
  739.   # syntax: register_x_lib_dir_with_ld_so
  740.   #
  741.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  742.   # libraries.
  743.   #
  744.   # Call this function from the postinst script of a package that places a
  745.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  746.  
  747.   local dir ldsoconf
  748.  
  749.   dir="/usr/X11R6/lib"
  750.   ldsoconf="/etc/ld.so.conf"
  751.  
  752.   # is the line not already present?
  753.   if ! fgrep -qsx "$dir" "$ldsoconf"; then
  754.     observe "adding $dir directory to $ldsoconf"
  755.     echo "$dir" >> "$ldsoconf"
  756.   fi
  757. }
  758.  
  759. deregister_x_lib_dir_with_ld_so () {
  760.   # syntax: deregister_x_lib_dir_with_ld_so
  761.   #
  762.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  763.   # libraries, if and only if no shared libaries remain there.
  764.   #
  765.   # Call this function from the postrm script of a package that places a shared
  766.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  767.   # invoking ldconfig.
  768.  
  769.   local dir ldsoconf fgrep_status cmp_status
  770.  
  771.   dir="/usr/X11R6/lib"
  772.   ldsoconf="/etc/ld.so.conf"
  773.  
  774.   # is the line present?
  775.   if fgrep -qsx "$dir" "$ldsoconf"; then
  776.     # are there any shared objects in the directory?
  777.     if [ "$(echo "$dir"/lib*.so.*.*)" = "$dir/lib*.so.*.*" ]; then
  778.       # glob expansion produced nothing, so no shared libraries are present
  779.       observe "removing $dir directory from $ldsoconf"
  780.       # rewrite the file (very carefully)
  781.       set +e
  782.       fgrep -svx "$dir" "$ldsoconf" > "$ldsoconf.dpkg-tmp"
  783.       fgrep_status=$?
  784.       set -e
  785.       case $fgrep_status in
  786.         0|1) ;; # we don't actually care if any lines matched or not
  787.         *) die "error reading \"$ldsoconf\"; fgrep exited with status" \
  788.           "$fgrep_status" ;;
  789.       esac
  790.       set +e
  791.       cmp -s "$ldsoconf.dpkg-tmp" "$ldsoconf"
  792.       cmp_status=$?
  793.       set -e
  794.       case $cmp_status in
  795.         0) rm "$ldsoconf.dpkg-tmp" ;; # files are identical
  796.         1) mv "$ldsoconf.dpkg-tmp" "$ldsoconf" ;; # files differ
  797.         *) die "error comparing \"$ldsoconf.dpkg-tmp\" to \"$ldsoconf\";" \
  798.           "cmp exited with status $cmp_status" ;;
  799.       esac
  800.     fi
  801.   fi
  802. }
  803.  
  804. make_symlink_sane () {
  805.   # syntax: make_symlink_sane symlink target
  806.   #
  807.   # Ensure that the symbolic link symlink exists, and points to target.
  808.   #
  809.   # If symlink does not exist, create it and point it at target.
  810.   #
  811.   # If symlink exists but is not a symbolic link, back it up.
  812.   #
  813.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  814.   # it.
  815.   #
  816.   # If symlink exists, is a symbolic link, and already points to target, do
  817.   # nothing.
  818.   #
  819.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  820.  
  821.   # Validate arguments.
  822.   if [ $# -ne 2 ]; then
  823.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  824.       "expected 2, got $#"
  825.     exit $SHELL_LIB_USAGE_ERROR
  826.   fi
  827.  
  828.   # We could just use the positional parameters as-is, but that makes things
  829.   # harder to follow.
  830.   local symlink target
  831.  
  832.   symlink="$1"
  833.   target="$2"
  834.  
  835.   if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
  836.       observe "link from $symlink to $target already exists"
  837.   else
  838.     observe "creating symbolic link from $symlink to $target"
  839.     mkdir -p "${target%/*}" "${symlink%/*}"
  840.     ln -s -b -S ".dpkg-old" "$target" "$symlink"
  841.   fi
  842. }
  843.  
  844. migrate_dir_to_symlink () {
  845.   # syntax: migrate_dir_to_symlink old_location new_location
  846.   #
  847.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  848.   # symbolic link to a directory or vice versa; instead, the existing state
  849.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  850.   # there is one."
  851.   #
  852.   # We have to do it ourselves.
  853.   #
  854.   # This function moves the contents of old_location, a directory, into
  855.   # new_location, a directory, then makes old_location a symbolic link to
  856.   # new_location.
  857.   #
  858.   # old_location need not exist, but if it does, it must be a directory (or a
  859.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  860.   # exists already and is not a directory, it is backed up.
  861.   #
  862.   # This function should be called from a package's preinst so that other
  863.   # packages unpacked after this one --- but before this package's postinst runs
  864.   # --- are unpacked into new_location even if their payloads contain
  865.   # old_location filespecs.
  866.  
  867.   # Validate arguments.
  868.   if [ $# -ne 2 ]; then
  869.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  870.                 "arguments; expected 2, got $#"
  871.     exit $SHELL_LIB_USAGE_ERROR
  872.   fi
  873.  
  874.   # We could just use the positional parameters as-is, but that makes things
  875.   # harder to follow.
  876.   local new old
  877.  
  878.   old="$1"
  879.   new="$2"
  880.  
  881.   # Is old location a symlink?
  882.   if [ -L "$old" ]; then
  883.     # Does it already point to new location?
  884.     if [ "$(readlink "$old")" = "$new" ]; then
  885.       # Nothing to do; migration has already been done.
  886.       observe "migration of $old to $new already done"
  887.       return 0
  888.     else
  889.       # Back it up.
  890.       warn "backing up symbolic link $old as $old.dpkg-old"
  891.       mv -b "$old" "$old.dpkg-old"
  892.     fi
  893.   fi
  894.  
  895.   # Does old location exist, but is not a directory?
  896.   if [ -e "$old" ] && ! [ -d "$old" ]; then
  897.       # Back it up.
  898.       warn "backing up non-directory $old as $old.dpkg-old"
  899.       mv -b "$old" "$old.dpkg-old"
  900.   fi
  901.  
  902.   observe "migrating $old to $new"
  903.  
  904.   # Is new location a symlink?
  905.   if [ -L "$new" ]; then
  906.     # Does it point the wrong way, i.e., back to where we're migrating from?
  907.     if [ "$(readlink "$new")" = "$old" ]; then
  908.       # Get rid of it.
  909.       observe "removing symbolic link $new which points to $old"
  910.       rm "$new"
  911.     else
  912.       # Back it up.
  913.       warn "backing up symbolic link $new as $new.dpkg-old"
  914.       mv -b "$new" "$new.dpkg-old"
  915.     fi
  916.   fi
  917.  
  918.   # Does new location exist, but is not a directory?
  919.   if [ -e "$new" ] && ! [ -d "$new" ]; then
  920.     warn "backing up non-directory $new as $new.dpkg-old"
  921.     mv -b "$new" "$new.dpkg-old"
  922.   fi
  923.  
  924.   # Create new directory if it does not yet exist.
  925.   if ! [ -e "$new" ]; then
  926.     observe "creating $new"
  927.     mkdir -p "$new"
  928.   fi
  929.  
  930.   # Copy files in old location to new location.  Back up any filenames that
  931.   # already exist in the new location with the extension ".dpkg-old".
  932.   observe "copying files from $old to $new"
  933.   if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
  934.     die "error(s) encountered while copying files from $old to $new"
  935.   fi
  936.  
  937.   # Remove files at old location.
  938.   observe "removing $old"
  939.   rm -r "$old"
  940.  
  941.   # Create symlink from old location to new location.
  942.   make_symlink_sane "$old" "$new"
  943. }
  944.  
  945. # vim:set ai et sw=2 ts=2 tw=80:
  946.  
  947. # GOBSTOPPER: The X Strike Force shell library ends here.
  948.  
  949. if [ -e /etc/default/xorg ]; then
  950.   . /etc/default/xorg
  951. fi
  952.  
  953. if [ "x$XORG_CONFIG" = "xcustom" ]; then
  954.   # leave configuration alone
  955.   warn "not updating configuration as per \$XORG_CUSTOM"
  956.   exit 0
  957. fi
  958.  
  959. # the error-out function
  960. bomb () {
  961.   echo "$PROGNAME: error: $*" | fold -s -w "${COLUMNS:-80}" >&2
  962.   exit 1
  963. }
  964.  
  965. debug_echo () {
  966.   # Syntax: debug_echo message ...
  967.   if [ -n "$DEBUG_XORG_DEBCONF" ] || [ "$DEBCONF_DEBUG" = "user" ] \
  968.     || [ "$DEBCONF_DEBUG" = '.*' ]; then
  969.     DEBUG_XORG_PACKAGE="yes" observe "$*"
  970.   fi
  971. }
  972.  
  973. validate_string_db_input () {
  974.   # Syntax: validate_string_db_input priority template
  975.   #
  976.   # validate string input; can't have doublequotes
  977.   # If $MAY_BE_NULL is a non-null value (e.g., "yes"), the string may be null.
  978.   if [ $# -ne 2 ]; then
  979.     echo "internal error: validate_string_db_input() called with wrong number of arguments: $*" >&2
  980.     exit 1
  981.   fi
  982.   PRIORITY="$1"
  983.   TEMPLATE="$2"
  984.   db_get "$TEMPLATE"
  985.   SAFE="$RET"
  986.   set +e
  987.   while :; do
  988.     db_input "$PRIORITY" "$TEMPLATE"
  989.     # is the question going to be asked?
  990.     if [ $? -eq 30 ]; then
  991.       break # no; bail out of validation loop
  992.     fi
  993.     db_go
  994.     db_get "$TEMPLATE"
  995.     if [ -n "$RET" ]; then
  996.       if ! expr "$RET" : '.*".*' > /dev/null 2>&1; then
  997.         break # valid input
  998.       else
  999.         ERROR="xserver-xorg/config/doublequote_in_string_error"
  1000.       fi
  1001.     else
  1002.       if [ -n "$MAY_BE_NULL" ]; then
  1003.         break # valid (null) input
  1004.       else
  1005.         ERROR="xserver-xorg/config/null_string_error"
  1006.       fi
  1007.     fi
  1008.     # we only get to this point if the input was invalid; restore the known
  1009.     # good value in case we are interrupted before the user provides a valid
  1010.     # one
  1011.     db_set "$TEMPLATE" "$SAFE"
  1012.     db_fset "$TEMPLATE" seen false
  1013.     # now show the user the error message
  1014.     db_fset "$ERROR" seen false
  1015.     db_input critical "$ERROR"
  1016.     db_go
  1017.   done
  1018.   set -e
  1019. }
  1020.  
  1021. CONFIG_DIR="/etc/X11"
  1022. CONFIG_AUX_DIR=/var/lib/x11
  1023. SERVER_SYMLINK="$CONFIG_DIR/X"
  1024. XORGCONFIG="$CONFIG_DIR/xorg.conf"
  1025. CONFIG_AUX_DIR="/var/lib/x11"
  1026. SERVER_SYMLINK_CHECKSUM="$CONFIG_AUX_DIR/${SERVER_SYMLINK##*/}.md5sum"
  1027. SERVER_SYMLINK_ROSTER="$CONFIG_AUX_DIR/${SERVER_SYMLINK##*/}.roster"
  1028. XORGCONFIG_CHECKSUM="$CONFIG_AUX_DIR/${XORGCONFIG##*/}.md5sum"
  1029. XORGCONFIG_ROSTER="$CONFIG_AUX_DIR/${XORGCONFIG##*/}.roster"
  1030. THIS_SERVER=/usr/bin/Xorg
  1031.  
  1032. NCARDS=0
  1033. NSERVERS=0
  1034. NDRIVERS=0
  1035. DRIVERS_LIST=
  1036. MULTIHEAD=
  1037.  
  1038. # get machine architecture
  1039. ARCH=$(dpkg --print-installation-architecture)
  1040.  
  1041. debug_echo () {
  1042.   # Syntax: debug_echo message ...
  1043.   if [ -n "$DEBUG_XORG_DEBCONF" ] || [ "$DEBCONF_DEBUG" = "user" ] \
  1044.     || [ "$DEBCONF_DEBUG" = '.*' ]; then
  1045.     DEBUG_XORG_PACKAGE=yes observe "$*"
  1046.   fi
  1047. }
  1048.  
  1049. debug_report_status () {
  1050.   # Syntax: debug_report_status command exit_status
  1051.   debug_echo "$1 exited with status $2"
  1052. }
  1053.  
  1054. discover_sparc_video () {
  1055.   # Detect video cards on sparc by parsing prtconf output
  1056.   prtconf -p -v | awk '
  1057.   BEGIN {
  1058.           display_node = 0; 
  1059.           model = ""; 
  1060.           name = ""; 
  1061.   }
  1062.   /Node/ {
  1063.            if(display_node == 1) {
  1064.              printf "model=\"%s\" name=\"%s\"\n", model, name
  1065.              display_node = 0;
  1066.            };
  1067.            model = "";
  1068.            name = ""
  1069.   }
  1070.   /device_type:/ {
  1071.                    if(index($2, "display") != 0) {
  1072.                      display_node = 1
  1073.                    }
  1074.   }
  1075.   /model:/ { l=length($2); model = substr($2, 2, l-2) }
  1076.   /name:/  { l=length($2); name = substr($2, 2, l-2) }
  1077.   END{
  1078.        if(display_node == 1) {
  1079.          printf "model=\"%s\" name=\"%s\"\n", model, name
  1080.        }; 
  1081.   }' | \
  1082.   while read line
  1083.   do
  1084.     eval "${line}"
  1085. #   Match the name and the model to the driver.
  1086.     test -z "${name}" && continue
  1087. #   The model stored in the prom is usually not too
  1088. #   informative, so that we need to provide some
  1089. #   sensible human-readable card identification as well.
  1090.     server='XFree86'
  1091.     case "${name}" in
  1092.       'cgsix' )
  1093.         card='Sun CG6 framebuffer'
  1094.         driver='suncg6' 
  1095.     ;;
  1096.       'SUNW,sx' )
  1097.         card='Sun CG14 framebuffer'
  1098.         driver='suncg14'
  1099.         ;;
  1100.       'SUNW,leo' )
  1101.         card='Sun LEO framebuffer'
  1102.         driver='sunleo'
  1103.         ;;
  1104.       'SUNW,tcx' )
  1105.         card='Sun TCX framebuffer' 
  1106.         driver='suntcx'
  1107.     ;;
  1108.       'SUNW,m64B' )
  1109.         card='ATI Technologies 3D Rage Pro or similar'
  1110.         driver='ati'
  1111.         ;;
  1112.       'SUNW,ffb' )
  1113.         card='Sun Creator3D framebuffer or similar'
  1114.         driver='sunffb'
  1115.         ;;
  1116.       'SUNW,afb' )
  1117.         card='Sun Elite3D framebuffer or similar'
  1118.         driver='sunffb'
  1119.         ;;
  1120.       'TSI,gfxp' )
  1121.         card='PGX32 framebuffer or similar'
  1122.         driver='glint'
  1123.         ;;
  1124.       * )
  1125.         card='Unknown'
  1126.         server='unknown'
  1127.         driver='unknown'
  1128.         ;;
  1129.     esac
  1130.     if [ -n "${model}" ]; then
  1131.       card="${card} (${model})"
  1132.     fi
  1133.     printf "${card}\t${server}\t${driver}\n"
  1134.   done
  1135. }
  1136.  
  1137. validate_string_db_input () {
  1138.   # Syntax: validate_string_db_input priority template
  1139.   #
  1140.   # validate string input; can't have doublequotes
  1141.   # If $MAY_BE_NULL is a non-null value (e.g., "yes"), the string may be null.
  1142.   if [ $# -ne 2 ]; then
  1143.     echo "internal error: validate_string_db_input() called with wrong number of arguments: $*" >&2
  1144.     exit 1
  1145.   fi
  1146.   PRIORITY=$1
  1147.   TEMPLATE=$2
  1148.   db_get "$TEMPLATE"
  1149.   SAFE="$RET"
  1150.   set +e
  1151.   while :; do
  1152.     db_input "$PRIORITY" "$TEMPLATE"
  1153.     # is the question going to be asked?
  1154.     if [ $? -eq 30 ]; then
  1155.       break # no; bail out of validation loop
  1156.     fi
  1157.     db_go
  1158.     db_get "$TEMPLATE"
  1159.     if [ -n "$RET" ]; then
  1160.       if ! expr "$RET" : '.*".*' > /dev/null 2>&1; then
  1161.         break # valid input
  1162.       else
  1163.         ERROR=xserver-xorg/config/doublequote_in_string_error
  1164.       fi
  1165.     else
  1166.       if [ -n "$MAY_BE_NULL" ]; then
  1167.         break # valid (null) input
  1168.       else
  1169.         ERROR=xserver-xorg/config/null_string_error
  1170.       fi
  1171.     fi
  1172.     # we only get to this point if the input was invalid; restore the known
  1173.     # good value in case we are interrupted before the user provides a valid
  1174.     # one
  1175.     db_set "$TEMPLATE" "$SAFE"
  1176.     db_fset "$TEMPLATE" seen false
  1177.     # now show the user the error message
  1178.     db_fset "$ERROR" seen false
  1179.     db_input critical "$ERROR"
  1180.     db_go
  1181.   done
  1182.   set -e
  1183. }
  1184.  
  1185. validate_numeric_db_input () {
  1186.   # Syntax: validate_numeric_db_input priority template
  1187.   #
  1188.   # validate numeric input; must have only digits, can be null
  1189.   if [ $# -ne 2 ]; then
  1190.     echo "internal error: validate_numeric_db_input() called with wrong number of arguments: $*" >&2
  1191.     exit 1
  1192.   fi
  1193.   PRIORITY=$1
  1194.   TEMPLATE=$2
  1195.   db_get "$TEMPLATE"
  1196.   SAFE="$RET"
  1197.   set +e
  1198.   while :; do
  1199.     db_input "$PRIORITY" "$TEMPLATE"
  1200.     # is the question going to be asked?
  1201.     if [ $? -eq 30 ]; then
  1202.       break # no; bail out of validation loop
  1203.     fi
  1204.     db_go
  1205.     db_get "$TEMPLATE"
  1206.     if [ -z "$RET" ] || expr "$RET" : "[0-9]\+$" > /dev/null 2>&1; then
  1207.       break # valid input
  1208.     fi
  1209.     # we only get to this point if the input was invalid; restore the known
  1210.     # good value in case we are interrupted before the user provides a valid
  1211.     # one
  1212.     db_set "$TEMPLATE" "$SAFE"
  1213.     db_fset "$TEMPLATE" seen false
  1214.     # now show the user the error message
  1215.     db_fset xserver-xorg/config/nonnumeric_string_error seen false
  1216.     db_input critical xserver-xorg/config/nonnumeric_string_error
  1217.     db_go
  1218.   done
  1219.   set -e
  1220. }
  1221.  
  1222. validate_bus_id_db_input () {
  1223.   # Syntax: validate_bus_id_db_input priority template
  1224.   #
  1225.   # validate BusID input
  1226.   if [ $# -ne 2 ]; then
  1227.     echo "internal error: validate_bus_id_db_input() called with wrong number of arguments: $*" >&2
  1228.     exit 1
  1229.   fi
  1230.   PRIORITY=$1
  1231.   TEMPLATE=$2
  1232.   db_get "$TEMPLATE"
  1233.   SAFE="$RET"
  1234.   set +e
  1235.   while :; do
  1236.     db_input "$PRIORITY" "$TEMPLATE"
  1237.     # is the question going to be asked?
  1238.     if [ $? -eq 30 ]; then
  1239.       break # no; bail out of validation loop
  1240.     fi
  1241.     db_go
  1242.     db_get "$TEMPLATE"
  1243.     case "$RET" in
  1244.       "")
  1245.         # An empty string is valid.
  1246.         break
  1247.         ;;
  1248.       ISA:*)
  1249.         # Looks like an ISA bus ID specification string.  At least up to a
  1250.         # point; upstream (xf86ParseIsaBusString() in
  1251.         # xc/programs/Xserver/hw/xfree86/common/xf86isaBus.c) doesn't actually
  1252.         # *supply* a specification.  So if the user's gotten this far, it's good
  1253.         # enough.
  1254.         break
  1255.         ;;
  1256.       PCI:*)
  1257.         # Looks like a PCI bus ID specification; validate it.  (We can use &&
  1258.         # outside a conditional here because of the "set +e" above.)
  1259.         expr "$RET" : "PCI:[0-9]\{1,3\}:[0-9]\{1,3\}:[0-9]\{1,3\}$" >/dev/null \
  1260.           2>&1 && break
  1261.         ;;
  1262.       SBUS:*)
  1263.         # Looks like an SBUS bus ID specification; validate it.  (We can use &&
  1264.         # outside a conditional here because of the "set +e" above.)
  1265.         #
  1266.         # According to upstream (xf86ParseSbusBusString() in
  1267.         # xc/programs/Xserver/hw/xfree86/common/xf86sbusBus.c):
  1268.         #
  1269.         # The format is assumed to be one of:
  1270.         # * "fbN", e.g. "fb1", which means the device corresponding to /dev/fbN
  1271.         # * "nameN", e.g. "cgsix0", which means Nth instance of card NAME
  1272.         # * "/prompath", e.g. "/sbus@0,10001000/cgsix@3,0" which is
  1273.         #   PROM pathname to the device.
  1274.         #
  1275.         # Well, okay.
  1276.         #
  1277.         # Accept any non-null sequence of lowercase letters followed by a
  1278.         # non-null sequence of decimal digits.  This handles "fbN" and "nameN".
  1279.         expr "$RET" : "SBUS:[a-z]\+[0-9]\+" >/dev/null 2>&1 && break
  1280.         # Now for the PROM path.  I am lazy; accept a slash followed a non-null
  1281.         # sequence of letters and commas, an at sign, a non-null sequence of
  1282.         # hexadecimal digits, a comma, and another non-null sequence of
  1283.         # hexadecimal digits.  Furthermore, accept multiple occurences of this
  1284.         # entire sequence.  Whew.
  1285.         expr "$RET" : "SBUS:\(/[A-Za-z,]\+@[0-9A-Fa-f]\+,[0-9A-Fa-f]\+\)\+$" \
  1286.           >/dev/null 2>&1 && break
  1287.         ;;
  1288.       [0-9])
  1289.         # Accept a simple decimal integer for legacy buses that haven't been
  1290.         # properly implemented (e.g., for SGI Indigo2 XL).
  1291.         break
  1292.         ;;
  1293.       *)
  1294.     esac
  1295.     # we only get to this point if the input was invalid; restore the known good
  1296.     # value in case we are interrupted before the user provides a valid one
  1297.     db_set "$TEMPLATE" "$SAFE"
  1298.     db_fset "$TEMPLATE" seen false
  1299.     # now show the user the error message
  1300.     db_fset xserver-xorg/config/device/bus_id_error seen false
  1301.     db_input critical xserver-xorg/config/device/bus_id_error
  1302.     db_go
  1303.   done
  1304.   set -e
  1305. }
  1306.  
  1307. auto_answer () {
  1308.   # Syntax: auto_answer input_command priority template default_answer
  1309.   #
  1310.   # Used to auto-answer questions that don't have reasonable defaults.  Some
  1311.   # people insist on running the xserver-xorg config script with the
  1312.   # non-interactive frontend.  For this to work, the debconf database will need
  1313.   # to be pre-loaded with answers to several questions.  You have been
  1314.   # warned...
  1315.   if [ $# -ne 4 ]; then
  1316.     echo "internal error: auto_answer() called with wrong number of arguments: $*" >&2
  1317.     exit 1
  1318.   fi
  1319.   INPUT_COMMAND=$1
  1320.   PRIORITY=$2
  1321.   TEMPLATE=$3
  1322.   DEFAULT_ANSWER=$4
  1323.   set +e
  1324.   debug_echo "auto_answer() \"$INPUT_COMMAND $PRIORITY $TEMPLATE\" with default \"$DEFAULT_ANSWER\""
  1325.   db_fget "$TEMPLATE" seen
  1326.   # are we re-configuring?
  1327.   if [ -z "$FIRSTINST" ] && [ "$RET" = "true" ]; then
  1328.     # yes, we are reconfiguring
  1329.     db_get "$TEMPLATE"
  1330.     debug_echo "auto_answer: (reconfiguring) preserving existing answer \"$RET\""
  1331.   else
  1332.     # not reconfiguring; has the question been seen before?
  1333.     if [ "$RET" = "true" ]; then
  1334.       db_get "$TEMPLATE"
  1335.       debug_echo "auto_answer: (not reconfiguring) preserving existing answer \"$RET\""
  1336.     else
  1337.       debug_echo "auto_answer: auto-answering with \"$DEFAULT_ANSWER\""
  1338.       db_set $TEMPLATE "$DEFAULT_ANSWER"
  1339.     fi
  1340.   fi
  1341.   "$INPUT_COMMAND" "$PRIORITY" "$TEMPLATE"
  1342.   if [ $? -eq 30 ]; then
  1343.     debug_echo "auto_answer: $TEMPLATE is not being asked"
  1344.   else
  1345.     debug_echo "auto_answer: asking $TEMPLATE"
  1346.   fi
  1347.   set -e
  1348.   db_go
  1349.   db_get "$TEMPLATE"
  1350.   debug_echo "auto_answer: $TEMPLATE is \"$RET\""
  1351. }
  1352.  
  1353. priority_ceil() {
  1354.   # syntax: priority_ceil requested_priority
  1355.   #
  1356.   # Given a variable PRIORITY_CEILING and a "requested_priority" argument, echo
  1357.   # a debconf priority string corresponding to the lesser of the two.
  1358.  
  1359.   # Implementation note: a clever version of this could be done using "eval",
  1360.   # or embedding a Perl script, but those would be more difficult to maintain.
  1361.   # Better just to go the simple and stupid route.  Yes, I know this is not
  1362.   # very efficient.
  1363.  
  1364.   # Validate arguments.
  1365.   if [ $# -ne 1 ]; then
  1366.     debug_echo "priority_ceil() called with empty or bogus arguments \"$*\";" \
  1367.                "assuming argument of \"low\""
  1368.     _requested_priority=low
  1369.   else
  1370.     _requested_priority="$1"
  1371.   fi
  1372.  
  1373.   # If PRIORITY_CEILING is null or unset, it's same as not having one at all;
  1374.   # the sky's the limit.  We use a locally scoped priority_ceiling variable
  1375.   # because we don't want to affect the value of the global one.
  1376.   _priority_ceiling=${PRIORITY_CEILING:-"critical"}
  1377.  
  1378.   # Ensure the value of _priority_ceiling is reasonable.
  1379.   if [ "$_priority_ceiling" != "critical" ] && \
  1380.        [ "$_priority_ceiling" != "high" ] && \
  1381.        [ "$_priority_ceiling" != "medium" ] && \
  1382.        [ "$_priority_ceiling" != "low" ]; then
  1383.     debug_echo "priority_ceil() called with bogus value of \$PRIORITY_CEILING" \
  1384.                "\"$_priority_ceiling\"; treating as \"critical\""
  1385.     _priority_ceiling=critical
  1386.   fi
  1387.  
  1388.   case "$_requested_priority" in
  1389.     critical)
  1390.       # This is the highest priority, so there is nowhere to go but down.
  1391.       echo "$_priority_ceiling"
  1392.       ;;
  1393.     high)
  1394.       case "$_priority_ceiling" in
  1395.         critical)
  1396.           echo "$_requested_priority"
  1397.           ;;
  1398.         high|medium|low)
  1399.           echo "$_priority_ceiling"
  1400.           ;;
  1401.       esac
  1402.       ;;
  1403.     medium)
  1404.       case "$_priority_ceiling" in
  1405.         critical|high)
  1406.           echo "$_requested_priority"
  1407.           ;;
  1408.         medium|low)
  1409.           echo "$_priority_ceiling"
  1410.           ;;
  1411.       esac
  1412.       ;;
  1413.     low)
  1414.       # This is the lowest priority, so we can't go any lower.
  1415.       echo "$_requested_priority"
  1416.       ;;
  1417.     *)
  1418.       debug_echo "priority_ceil() called with bogus argument" \
  1419.                  "\"$_requested_priority\"; returning \"low\""
  1420.       echo low
  1421.       ;;
  1422.   esac
  1423. }
  1424.  
  1425. non_latin_keyboard () {
  1426.   NONLATINMAPS="am ar bg by cs el gr il ir iu lo lt mk ml mm mn ru th tj ua"
  1427.   for i in $NONLATINMAPS; do
  1428.     if [ "$XMAP" = "$i" ]; then
  1429.       NON_LATIN="true"
  1430.     fi
  1431.   done
  1432.  
  1433.   # Turkish F keyboards are non-Latin; Turkish Q aren't.
  1434.   if [ "$XMAP" = "tr" ] && [ "$VARIANT" = "f" ]; then
  1435.     NON_LATIN="true"
  1436.   fi
  1437. }
  1438.  
  1439. # analyze arguments; used by auto_answer()
  1440. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  1441.   RECONFIGURE=true
  1442. else
  1443.   RECONFIGURE=
  1444. fi
  1445.  
  1446. if [ -z "$2" ]; then
  1447.   FIRSTINST=yes
  1448. fi
  1449.  
  1450. debug_echo "Configuring $THIS_PACKAGE."
  1451.  
  1452. # collect information about installed video card(s), if possible
  1453. if [ "$ARCH" = "sparc" ]; then
  1454.   DISCOVER_PROG='prtconf'
  1455.   DISCOVER_FUNC='discover_sparc_video'
  1456.  
  1457.   if which $DISCOVER_PROG > /dev/null 2>&1; then
  1458.     DISCOVERED_VIDEO=$($DISCOVER_FUNC)
  1459.     MULTIHEAD=$(echo "$DISCOVERED_VIDEO" | wc -l)
  1460.     if [ -n "$DISCOVERED_VIDEO" ]; then
  1461.       NCARDS=$(echo "$DISCOVERED_VIDEO" | wc -l)
  1462.       SERVERS=$(echo "$DISCOVERED_VIDEO" | awk 'BEGIN { FS="\t" } {print $2}' | grep -v unknown | sort | uniq)
  1463.       if [ -n "$SERVERS" ]; then
  1464.         NSERVERS=$(echo "$SERVERS" | wc -l)
  1465.       fi
  1466.       DRIVERS=$(echo "$DISCOVERED_VIDEO" | awk 'BEGIN { FS="\t" } {print $NF}' | grep -v unknown | sort | uniq)
  1467.       if [ -n "$DRIVERS" ]; then
  1468.         NDRIVERS=$(echo "$DRIVERS" | wc -l)
  1469.         DRIVERS_LIST=$(echo "$DRIVERS" | awk 'BEGIN {ORS="";FS="\t"} {if(NR > 1){print last ","};last=$0} END {print last}')
  1470.       fi
  1471.       if [ $MULTIHEAD -gt 1 ]; then
  1472.         MULTIHEAD=yes
  1473.       fi
  1474.       DISCOVERED_VIDEO=$(echo "$DRIVERS" | head -n 1)
  1475.     else
  1476.       DISCOVERED_VIDEO=""
  1477.     fi
  1478.   else
  1479.     DISCOVERED_VIDEO=""
  1480.   fi
  1481. else
  1482.   DISCOVERED_VIDEO=""
  1483. fi
  1484.  
  1485. if [ -n "$XFORCEVESA" ] || [ -n "$(grep xforcevesa /proc/cmdline)" ]; then
  1486.   # don't let the server autodetect the video card, but always use vesa instead
  1487.   DRIVERS_LIST="vesa"
  1488.   DISCOVERED_VIDEO="vesa"
  1489. fi
  1490.  
  1491. db_subst xserver-xorg/config/device/driver choices "$DRIVERS_LIST"
  1492. auto_answer db_input low xserver-xorg/config/device/driver "$DISCOVERED_VIDEO"
  1493.  
  1494. if [ -n "$FIRSTINST" ] || [ -n "$RECONFIGURE" ]; then
  1495.   # BusID
  1496.   PRIORITY=low
  1497.   DEFAULT=
  1498.  
  1499.   # Some PowerPCs need to be told where to find the video card even if there is
  1500.   # only one in the machine (broken PCI bus code in the XFree86 X server, most
  1501.   # likely).  If there are multiple video cards, we need to configure one as the
  1502.   # primary head.
  1503.   if [ "$ARCH" = "powerpc" ] || [ "$MULTIHEAD" = "yes" ]; then
  1504.     PRIORITY=medium
  1505.     if which lspci > /dev/null 2>&1; then
  1506.       # Try to guess the correct BusID.
  1507.       VIDEO_CARD=$(LC_ALL=C lspci -n | grep -E "(Class )?0300:" | sort -n | head -n 1 \
  1508.         | cut -d\  -f1)
  1509.       if [ -n "$VIDEO_CARD" ]; then
  1510.         # Recent versions of lspci report a four-digit domain as the first field.
  1511.         if expr "$VIDEO_CARD" : ".*:.*:.*\..*" >/dev/null 2>&1; then
  1512.           # We have an entry in "hex:hex:hex.hex" format; we need
  1513.           # "PCI:decimal:decimal:decimal" (we don't use the domain).
  1514.           DOMAIN=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f1) )
  1515.           BUS=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f2) )
  1516.           DEVICE=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f3 | cut -d. -f1) )
  1517.           FUNCTION=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d. -f2) )
  1518.           DEFAULT="PCI:$BUS:$DEVICE:$FUNCTION"
  1519.         elif expr "$VIDEO_CARD" : ".*:.*\..*" >/dev/null 2>&1; then
  1520.           # We have an entry in "hex:hex.hex" format; we need
  1521.           # "PCI:decimal:decimal:decimal".
  1522.           BUS=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f1) )
  1523.           DEVICE=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f2 | cut -d. -f1) )
  1524.           FUNCTION=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d. -f2) )
  1525.           DEFAULT="PCI:$BUS:$DEVICE:$FUNCTION"
  1526.         else
  1527.           warn "unrecognized output from lspci: \"$VIDEO_CARD\""
  1528.         fi
  1529.       fi
  1530.     fi
  1531.   fi
  1532.  
  1533.   # SGI Indigo2 XLs require a special hack, per Guido Guenther (see Debian
  1534.   # #249614).
  1535.   if [ -e /proc/cpuinfo ]; then
  1536.     if grep -q "system type.*:.*SGI Indigo2" /proc/cpuinfo; then
  1537.       PRIORITY=medium
  1538.       DEFAULT=1
  1539.     fi
  1540.   fi
  1541.  
  1542.   # For most people, asking this question at all is a bad idea. Only do it
  1543.   # if we have a need to do so, as defined by setting the priority
  1544.   if [ "$PRIORITY" = "medium" ]; then
  1545.     # this question requires input validation
  1546.     if [ -n "$DEFAULT" ]; then
  1547.       auto_answer validate_bus_id_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/device/bus_id "$DEFAULT"
  1548.     else
  1549.       validate_bus_id_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/device/bus_id || debug_report_status "validate_bus_id_db_input $(priority_ceil $PRIORITY) xserver-xorg/config/device/bus_id" "$?"
  1550.     fi
  1551.   else
  1552.     db_set xserver-xorg/config/device/bus_id ""
  1553.   fi
  1554.  
  1555.   # use fbcon kernel functions?
  1556.  
  1557.   case "$ARCH" in
  1558.     alpha|hurd-i386|i386|amd64|lpia)
  1559.       USE_FBDEV=false
  1560.       ;;
  1561.     *)
  1562.       USE_FBDEV=true
  1563.       ;;
  1564.   esac
  1565.  
  1566.   if [ -e /proc/fb ]; then
  1567.     FB_TYPE="$(grep '^0 ' /proc/fb | sed 's/[^[:space:]] //')"
  1568.     # did we actually get back anything?
  1569.     if [ -n "$FB_TYPE" ]; then
  1570.       if echo "$FB_TYPE" | grep -Eiq '(OFfb|VESA|VGA16)'; then
  1571.         USE_FBDEV=false
  1572.       else
  1573.         # other framebuffers do support UseFBDEV
  1574.         USE_FBDEV=true
  1575.       fi
  1576.     fi
  1577.   else
  1578.     USE_FBDEV=false
  1579.   fi
  1580.  
  1581.   if [ -n "$XORG_USE_FBDEV" ] && [ "$XORG_USE_FBDEV" = "no" ]; then
  1582.     USE_FBDEV=false
  1583.   fi
  1584.  
  1585.   db_get xserver-xorg/config/device/use_fbdev || debug_report_status "db_get xserver-xorg/config/device/use_fbdev"
  1586.   if [ "$RET" = "true" ] && [ "$USE_FBDEV" = "false" ]; then
  1587.     debug_echo "xserver-xorg/config/device/use_fbdev is \"true\" but /proc/fb does not exist, is empty, or reports a framebuffer type with which UseFBDev cannot be used; setting template to \"false\""
  1588.     db_set xserver-xorg/config/device/use_fbdev false
  1589.   fi
  1590.  
  1591.   auto_answer db_input "$(priority_ceil medium)" xserver-xorg/config/device/use_fbdev "$USE_FBDEV"
  1592. fi
  1593.  
  1594. # keyboard setup
  1595. PRIORITY="medium"
  1596.  
  1597. if [ -n "$FIRSTINST" ]; then
  1598.   AUTODETECT_KB="true"
  1599. else
  1600.   AUTODETECT_KB="false"
  1601. fi
  1602.  
  1603. auto_answer db_input "$(priority_ceil $PRIORITY)" xserver-xorg/autodetect_keyboard "$AUTODETECT_KB" || debug_echo "db_input xserver-xorg/autodetect_keyboard"
  1604. db_get xserver-xorg/autodetect_keyboard || debug_report_status "db_get server-xorg/autodetect_keyboard"
  1605. if [ "$RET" = "true" ]; then
  1606.   DOKBDETECT="true"
  1607.   debug_echo "Redetecting keyboard layout; resetting flag to false."
  1608.   db_set xserver-xorg/autodetect_keyboard false
  1609. fi
  1610.  
  1611. if [ -n "$DOKBDETECT" ] && [ -f /etc/default/console-setup ]; then
  1612.   # Hmm. At least for now, none of the variables in this file will clash
  1613.   # with our own variables ...
  1614.   . /etc/default/console-setup
  1615. fi
  1616.  
  1617. if [ "$XKBLAYOUT" ]; then
  1618.   debug_echo "Fetched keyboard layout from console configuration:"
  1619.   debug_echo "layout: '$XKBLAYOUT', options: '$XKBOPTIONS', variant: '$XKBVARIANT', model: '$XKBMODEL'"
  1620.   PRIORITY=low
  1621. elif [ -n "$DOKBDETECT" ]; then
  1622.   # generated by a small bit of Perl from a static list of keymaps provided
  1623.   # by Matthias Urlichs
  1624.   REALLANG=${LANG%%@*}
  1625.   REALLANG=${REALLANG%%.*}
  1626.  
  1627.   db_get debian-installer/keymap || debug_report_status "db_get debian-installer/keymap"
  1628.   DI_KEYMAP="${RET##mac-usb-}"
  1629.   DI_KEYMAP="${DI_KEYMAP%%-latin1}"
  1630.  
  1631.   case "$DI_KEYMAP" in
  1632.     be2) XMAP="be";;
  1633.     bg) XMAP="bg"; VARIANT="bds";;
  1634.     br) XMAP="us"; VARIANT="intl"; MODEL="pc104";;
  1635.     br-abnt2) XMAP="br"; VARIANT="abnt2"; MODEL="abnt2";;
  1636.     by) XMAP="by";;
  1637.     ca-multi) XMAP="ca"; VARIANT="multi";;
  1638.     cf) XMAP="ca"; VARIANT="fr";;
  1639.     croat) XMAP="hr";;
  1640.     cz-lat2) XMAP="cz";;
  1641.     de-latin1-nodeadkeys) XMAP="de"; VARIANT="nodeadkeys";;
  1642.     de) XMAP="de";;
  1643.     dvorak) XMAP="us"; VARIANT="dvorak"; MODEL="pc104";;
  1644.     dk) XMAP="dk";;
  1645.     es) XMAP="es";;
  1646.     et) XMAP="ee";;
  1647.     fi) XMAP="fi";;
  1648.     fr) XMAP="fr"; VARIANT="oss";;
  1649.     fr_CH) XMAP="ch"; VARIANT="fr";;
  1650.     fr-latin9) XMAP="fr"; VARIANT="latin9";;
  1651.     gb) XMAP="gb";;
  1652.     gr) XMAP="gr";;
  1653.     hebrew) XMAP="il";;
  1654.     hu) XMAP="hu";;
  1655.     is) XMAP="is";;
  1656.     it) XMAP="it";;
  1657.     jp106) XMAP="jp"; MODEL="jp106";;
  1658.     la) XMAP="latam";;
  1659.     lfc-cat) XMAP="es"; VARIANT="cat";;
  1660.     lt) XMAP="lt";;
  1661.     lv-latin4) XMAP="lv";;
  1662.     # XXX should these be MODEL="macintosh"?
  1663.     mac-us-std) XMAP="us";;
  1664.     mac-de2-ext) XMAP="de"; VARIANT="nodeadkeys";;
  1665.     mac-fr2-ext) XMAP="fr";;
  1666.     mac-fr3) XMAP="fr";;
  1667.     mac-es) XMAP="es";;
  1668.     mac-usb-de_CH) XMAP="ch"; VARIANT="de";;
  1669.     mk) XMAP="mk";;
  1670.     nl) XMAP="nl";;
  1671.     no) XMAP="no";;
  1672.     pl) XMAP="pl";;
  1673.     pt) XMAP="pt";;
  1674.     ro) XMAP="ro";;
  1675.     ru) XMAP="ru";;
  1676.     se) XMAP="se";;
  1677.     sg) XMAP="ch"; VARIANT="de";;
  1678.     sk-qwerty) XMAP="sk"; VARIANT="qwerty";;
  1679.     slovene) XMAP="si";;
  1680.     sr-cy) XMAP="cs";;
  1681.     trf|trfu) XMAP="tr"; VARIANT="f";;
  1682.     trq|trqu) XMAP="tr";;
  1683.     ua) XMAP="ua";;
  1684.     uk) XMAP="gb";;
  1685.     us) XMAP="us"; MODEL="pc104";;
  1686.     *) XMAP="UNKNOWN";;
  1687.   esac
  1688.  
  1689.   if [ "$XMAP" = "us" ] && [ "${DI_LANG}" = "ko_KR" ]; then
  1690.     XMAP=kr # Uses US keyboard on the console.
  1691.     MODEL=
  1692.   fi
  1693.  
  1694.   if [ "$XMAP" = "UNKNOWN" ]; then
  1695.     warn "failed to infer keyboard layout from layout/lang '$DI_KEYMAP--$REALLANG'"
  1696.     PRIORITY=medium
  1697.     XMAP="us"
  1698.     MODEL="pc104"
  1699.   # prompt for layout if we ended up with French Canadian; apparently having
  1700.   # US-layout keyboards is common there
  1701.   elif [ "$XMAP" = "ca" ] && [ "$VARIANT" = "fr" ]; then
  1702.     PRIORITY=high
  1703.   else
  1704.     PRIORITY=low
  1705.   fi
  1706.  
  1707.   # we can't do non-Latin usernames, so people with Latin layouts need a US
  1708.   # layout so they can log in, and then switch to writing native text.  Bit hard
  1709.   # to work out which one should be the default.
  1710.   non_latin_keyboard
  1711.   if [ -n "$NON_LATIN" ]; then
  1712.     warn "selected layout '$XMAP' from '$DI_KEYMAP--$REALLANG' is non-Latin; " \
  1713.          "adding us to the layout list, Alt+Shift toggles"
  1714.     if [ -z "$OPTIONS" ]; then
  1715.       OPTIONS="grp:alt_shift_toggle"
  1716.     else
  1717.       OPTIONS="$OPTIONS,grp:alt_shift_toggle"
  1718.     fi
  1719.     XMAP="us,$XMAP"
  1720.   fi
  1721.   
  1722.   if [ -n "$LEVEL2" ]; then
  1723.     warn "selected layout '$XMAP' from '$DI_KEYMAP--$REALLANG' is l2-only"
  1724.   fi
  1725.  
  1726.   XKBLAYOUT="$XMAP"
  1727.   XKBOPTIONS="$OPTIONS"
  1728.   XKBVARIANT="$VARIANT"
  1729.   XKBMODEL="$MODEL"
  1730. else
  1731.   db_get xserver-xorg/config/inputdevice/keyboard/layout || debug_report_status "db_get xserver-xorg/config/inputdevice/keyboard/layout"
  1732.   XKBLAYOUT="$RET"
  1733.   db_get xserver-xorg/config/inputdevice/keyboard/options || debug_report_status "db_get xserver-xorg/config/inputdevice/keyboard/options"
  1734.   XKBOPTIONS="$RET"
  1735.   db_get xserver-xorg/config/inputdevice/keyboard/variant || debug_report_status "db_get xserver-xorg/config/inputdevice/keyboard/variant"
  1736.   XKBVARIANT="$RET"
  1737.   db_get xserver-xorg/config/inputdevice/keyboard/model || debug_report_status "db_get xserver-xorg/config/inputdevice/keyboard/model"
  1738.   XKBMODEL="$RET"
  1739.   PRIORITY=low
  1740. fi
  1741.  
  1742. MAY_BE_NULL= auto_answer validate_string_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/inputdevice/keyboard/layout "$XKBLAYOUT"
  1743.  
  1744. # these questions require input validation
  1745. PRIORITY=medium
  1746.  
  1747. DEFAULT=xorg
  1748. MAY_BE_NULL= auto_answer validate_string_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/inputdevice/keyboard/rules "$DEFAULT"
  1749.  
  1750. if [ -z "$XKBMODEL" ]; then
  1751.   db_get xserver-xorg/config/inputdevice/keyboard/rules
  1752.   if [ "$RET" = "sun" ]; then
  1753.     db_set xserver-xorg/config/inputdevice/keyboard/rules "xorg"
  1754.     XKBMODEL=pc105
  1755.   elif [ "$RET" = "xorg" ]; then
  1756.     if [ "$ARCH" = "powerpc" ] && \
  1757.         [ -e /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ] && \
  1758.         [ "$(cat /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes)" = "0" ]; then
  1759.       XKBMODEL=macintosh_old
  1760.     else
  1761.       XKBMODEL=pc105
  1762.     fi
  1763.   fi
  1764. fi
  1765. MAY_BE_NULL= auto_answer validate_string_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/inputdevice/keyboard/model "$XKBMODEL"
  1766.  
  1767. # ugly kludge, I know; map Apple->AltGr for most European Macs
  1768. db_get xserver-xorg/config/inputdevice/keyboard/model
  1769. if [ "$ARCH" = "powerpc" ] && [ "$RET" = "pc105" ]; then
  1770.   if [ -n "$XKBOPTIONS" ]; then
  1771.     if ! echo "$XKBOPTIONS" | grep -q "lv3:"; then
  1772.       XKBOPTIONS="$XKBOPTIONS,lv3:lwin_switch"
  1773.     fi
  1774.   else
  1775.     XKBOPTIONS="lv3:lwin_switch"
  1776.   fi
  1777. fi
  1778.  
  1779. # kill me now.
  1780. if echo "$XKBOPTIONS" | grep -q "nodeadkeys"; then
  1781.   if [ -z "$XKBVARIANT" ]; then
  1782.     XKBVARIANT="nodeadkeys"
  1783.     NEWOPTIONS=""
  1784.     IFS_SAVE="$IFS"
  1785.     IFS=","
  1786.     for i in $XKBOPTIONS; do
  1787.       IFS="$IFS_SAVE"
  1788.       if [ "$i" != "nodeadkeys" ]; then
  1789.         NEWOPTIONS="${NEWOPTIONS:+$NEWOPTIONS,}$i"
  1790.       fi
  1791.       IFS=","
  1792.     done
  1793.     IFS="$IFS_SAVE"
  1794.     XKBOPTIONS="$NEWOPTIONS"
  1795.     db_set xserver-xorg/config/inputdevice/keyboard/variant "$XKBVARIANT"
  1796.     db_set xserver-xorg/config/inputdevice/keyboard/options "$XKBOPTIONS"
  1797.   else
  1798.     warn "wanted to migrate nodeadkeys from options -> variant, but variant" \
  1799.          "is already $XKBVARIANT; not migrating"
  1800.   fi
  1801. fi
  1802.  
  1803. MAY_BE_NULL=yes auto_answer validate_string_db_input "$(priority_ceil low)" xserver-xorg/config/inputdevice/keyboard/variant "$XKBVARIANT"
  1804.  
  1805. MAY_BE_NULL=yes auto_answer validate_string_db_input "$(priority_ceil $PRIORITY)" xserver-xorg/config/inputdevice/keyboard/options "$XKBOPTIONS"
  1806.  
  1807. # files and dri sections
  1808. if [ -e "$CONFIG_AUX_DIR/.migrateconfig" ]; then
  1809.   AUTODETECT_VIDEO="yes"
  1810.   rm -f $CONFIG_AUX_DIR/.migrateconfig
  1811. fi
  1812.  
  1813.  
  1814.  
  1815. # register this package as a (potential) handler of the X server symlink and
  1816. # X.Org X server configuration file
  1817. for ROSTER in "$SERVER_SYMLINK_ROSTER" "$XORGCONFIG_ROSTER"; do
  1818.   if ! fgrep -qsx "$THIS_PACKAGE" "$ROSTER"; then
  1819.     echo "$THIS_PACKAGE" >> "$ROSTER"
  1820.   fi
  1821. done
  1822.  
  1823. # only mess with the server symlink file if it is a symbolic link or does
  1824. # not exist.  otherwise, assume that's the way the user wants it.
  1825. if ! [ -e "$SERVER_SYMLINK" ]; then
  1826.   ln -s "$THIS_SERVER" "$SERVER_SYMLINK"
  1827. # recover from an old bug
  1828. elif [ `readlink "$SERVER_SYMLINK"` = "/bin/true" ]; then
  1829.   rm -f "$SERVER_SYMLINK"
  1830.   ln -s "$THIS_SERVER" "$SERVER_SYMLINK"
  1831. fi
  1832.  
  1833. if [ -n "$UPGRADE" ] && dpkg --compare-versions "$2" le "1:7.3+5"; then
  1834.         # Clean up our old crap
  1835.         rm -f "$SERVER_SYMLINK_CHECKSUM" "$SERVER_SYMLINK_ROSTER"
  1836.         for QUESTION in "shared/default-x-server" \
  1837.                         "xserver-xorg/autodetect_mouse" \
  1838.                         "xserver-xorg/autodetect_monitor" \
  1839.                         "xserver-xorg/autodetect_video_card" \
  1840.                         "xserver-xorg/config/device/identifier" \
  1841.                         "xserver-xorg/config/monitor/selection-method" \
  1842.                         "xserver-xorg/config/monitor/screen-size" \
  1843.                         "xserver-xorg/config/monitor/mode-list" \
  1844.                         "xserver-xorg/config/monitor/default-identifier" \
  1845.                         "xserver-xorg/config/monitor/horiz-sync" \
  1846.                         "xserver-xorg/config/monitor/vert-refresh" \
  1847.                         "xserver-xorg/config/monitor/range_input_error" \
  1848.                         "xserver-xorg/config/display/modes" \
  1849.                         "xserver-xorg/config/device/video_ram" \
  1850.                         "xserver-xorg/config/display/default_depth" \
  1851.                         "xserver-xorg/config/inputdevice/mouse/port" \
  1852.                         "xserver-xorg/config/inputdevice/mouse/protocol" \
  1853.                         "xserver-xorg/config/inputdevice/mouse/emulate3buttons" \
  1854.                         "xserver-xorg/config/modules" \
  1855.                         "xserver-xorg/config/monitor/default-identifier" \
  1856.                         "xserver-xorg/config/monitor/identifier" \
  1857.                         "xserver-xorg/config/write_files_section" \
  1858.                         "xserver-xorg/multiple_possible_x-drivers"; do
  1859.           db_unregister "$QUESTION" || true
  1860.         done
  1861. fi
  1862.  
  1863. # no debconf interaction should be done after this point
  1864. # (the dexconf call below invokes db_stop)
  1865.  
  1866. # Don't touch the config on upgrades except to deal with known issues with old
  1867. # configs.
  1868. if [ -n "$RECONFIGURE" ]; then
  1869.   # prepare a new version
  1870.   NEW_XORGCONFIG="$XORGCONFIG.dpkg-new"
  1871.   if [ -n "$RECONFIGURE" ] && [ -e "$XORGCONFIG" ]; then
  1872.     BACKUP_XORGCONFIG="$XORGCONFIG.$(date '+%Y%m%d%H%M%S')"
  1873.     if [ -e "$BACKUP_XORGCONFIG" ]; then
  1874.       bomb "backup xorg.conf file $BACKUP_XORGCONFIG already" \
  1875.            "exists; please remove it and try again"
  1876.     fi
  1877.     cp "$XORGCONFIG" "$BACKUP_XORGCONFIG"
  1878.     warn "overwriting possibly-customised configuration file; backup" \
  1879.          "in $BACKUP_XORGCONFIG"
  1880.   fi
  1881.   if dexconf -o "$NEW_XORGCONFIG"; then
  1882.     if ! cmp -s "$XORGCONFIG" "$NEW_XORGCONFIG"; then
  1883.       mv "$NEW_XORGCONFIG" "$XORGCONFIG"
  1884.       md5sum "$XORGCONFIG" > "$XORGCONFIG_CHECKSUM"
  1885.     fi
  1886.   else
  1887.     warn "error while preparing new Xorg X server configuration" \
  1888.          "file in $NEW_XORGCONFIG; not attempting to update existing" \
  1889.          "configuration"
  1890.   fi
  1891.   rm -f "$NEW_XORGCONFIG"
  1892. elif dpkg --compare-versions "$2" lt-nl "1:7.4~5ubuntu1"; then
  1893.   # We're upgrading from pre-7.4.  We need to replace i810 with intel,
  1894.   # via with openchrome, and psb with vesa.
  1895.   if [ -e "$XORGCONFIG" ]; then
  1896.     sed -e'
  1897.     /^[[:space:]]*Section[[:space:]]\+"Device"[[:space:]]*$/,/^[[:space:]]*EndSection[[:space:]]*$/ {
  1898.     /^[[:space:]]*Driver[[:space:]]\+"i810"/s/i810/intel/
  1899.     /^[[:space:]]*Driver[[:space:]]\+"via"/s/via/openchrome/
  1900.     /^[[:space:]]*Driver[[:space:]]\+"psb"/s/psb/vesa/
  1901.     }
  1902.     ' $XORGCONFIG > ${XORGCONFIG}.madwizard-new
  1903.     if ! cmp -s $XORGCONFIG ${XORGCONFIG}.madwizard-new; then
  1904.       # compare the current and stored checksums; if they do not match, assume
  1905.       # that's the way the user wants it.
  1906.       if [ "$(md5sum "$XORGCONFIG")" != "$(cat "$XORGCONFIG_CHECKSUM")" ]; then
  1907.         BACKUP_XORGCONFIG="$XORGCONFIG.$(date '+%Y%m%d%H%M%S')"
  1908.         warn "$XORGCONFIG has been customized, but we need to make updates. Backing up your config to $BACKUP_XORGCONFIG. If we screw something up, restore using this file."
  1909.         cp "$XORGCONFIG" "$BACKUP_XORGCONFIG"
  1910.       else
  1911.         # checksums match, update the checksum
  1912.         md5sum "${XORGCONFIG}.madwizard-new" > "$XORGCONFIG_CHECKSUM"
  1913.       fi
  1914.       chown --reference=$XORGCONFIG ${XORGCONFIG}.madwizard-new
  1915.       chmod --reference=$XORGCONFIG ${XORGCONFIG}.madwizard-new
  1916.       mv ${XORGCONFIG}.madwizard-new $XORGCONFIG
  1917.     else
  1918.       rm ${XORGCONFIG}.madwizard-new
  1919.     fi
  1920.   fi
  1921. else
  1922.   debug_echo "not updating $XORGCONFIG; we're upgrading"
  1923. fi
  1924.  
  1925. case "$1" in
  1926.   configure)
  1927.     if dpkg --compare-versions "$2" lt-nl "1:7.3+11"; then
  1928.       remove_conffile_commit "/etc/init.d/xserver-xorg"
  1929.     fi
  1930.     if dpkg --compare-versions "$2" lt-nl "1:7.3+13"; then
  1931.       update-rc.d xserver-xorg remove || true
  1932.     fi
  1933.     ;;
  1934. esac
  1935.  
  1936. exit 0
  1937.  
  1938. # vim:set ai et sts=2 sw=2 tw=0:
  1939.